﻿using _RobotInspection.Attributes;
using _RobotInspection.DTO;
using _RobotInspection.Entities;
using _RobotInspection.Interfaces;
using _RobotInspection.Models;
using Microsoft.AspNetCore.Mvc;

namespace _RobotInspection.Controllers
{
    /// <summary>
    /// 关注事项相关控制层
    /// </summary>
    [ApiController]
    [Route("[controller]/[action]")]
    public class AttentionItemController : ControllerBase
    {
        private readonly IAttentionItemService _service;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="service"></param>
        public AttentionItemController(IAttentionItemService service)
        {
            _service = service;
        }

        /// <summary>
        /// 分页获取关注事项
        /// </summary>
        /// <param name="queryDto"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult<ApiResponse<AttentionItemPagedResultDto>>> GetAttentionItemsPaged([FromQuery] AttentionItemPagedDto queryDto)
        {
            var result = await _service.GetAttentionItemsPagedAsync(queryDto);
            return new OkObjectResult(result);
        }

        /// <summary>
        /// 根据ID获取关注事项
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("{id}")]
        public async Task<ActionResult<ApiResponse<attention_item>>> GetAttentionItemByIdAsync([FromRoute] long id)
        {
            var result = await _service.GetAttentionItemByIdAsync(id);
            return new OkObjectResult(result);
        }

        /// <summary>
        /// 创建关注事项
        /// </summary>
        /// <param name="queryDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult<ApiResponse<attention_item>>> InsertAttentionItem([FromQuery] AttentionItemDto queryDto)
        {
            var result = await _service.InsertAttentionItemAsync(queryDto);
            return new OkObjectResult(result);
        }

        /// <summary>
        /// 删除关注项目
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("{id}")]
        public async Task<ActionResult<ApiResponse<attention_item?>>> DeleteAttentionItem([FromRoute] long id)
        {
            var result = await _service.DeleteAttentionItemAsync(id);
            return new OkObjectResult(result);
        }
    }
}
